package FilterPattern;

import java.util.List;

public class OrCriteria implements Criteria{
    private Criteria criteria;
    private Criteria otherCriteria;

    public OrCriteria(Criteria criteria, Criteria otherCriteria) {
        this.criteria = criteria;
        this.otherCriteria = otherCriteria;
    }

    public List<Person> meetCriteria(List<Person> persons) {
        List<Person> firstMeetPersons = criteria.meetCriteria(persons);
        List<Person> secondMeetPersons = otherCriteria.meetCriteria(persons);

        for(Person person : secondMeetPersons){
            if(!firstMeetPersons.contains(person)){
                firstMeetPersons.add(person);
            }
        }
        return firstMeetPersons;
    }
}
